package com.ts.main.admin.config;

import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.FormContentFilter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.List;

/**
 * @Author:lk
 * @Date: 2025/5/14  23:59
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {

    @Resource
    private AuthInterceptor authInterceptor;
    /**
     * 静态资源
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 放开knife4j的html拦截
        registry.addResourceHandler("/doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        // 放开knife4j的css和js拦截
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
        // 放开knife4j的图片拦截
        registry.addResourceHandler("/img/**")
                .addResourceLocations("classpath:/META-INF/resources/img/");
        // 放开静态资源
        registry.addResourceHandler("/file/**")
                .addResourceLocations("classpath:META-INF/resources/static/file/");
    }

    /**
     * 拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //放行路径
        List<String> excludePath = List.of(
                "/doc.html",
                "/swagger-ui.html",
                "/swagger-ui/**",
                "/swagger-resources/**",
                "/v3/api-docs/**",
                "/webjars/**",
                "/resources/**",
                "/static/**",
                "/error",
                "/favicon.ico");
        registry.addInterceptor(authInterceptor).excludePathPatterns(excludePath);
    }


    /**
     * 允许Restful风格的请求
     */
    @Component
    public class PutFilter extends FormContentFilter {

    }

}
